package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.ChanPin;
import com.ysd.util.DBManger;

public class ChanPinDaoImpl {
	//根据分类Id查询对应的产品列表
	//cpId 产品分类Id
	public List<ChanPin> getChanPinList(int cpId){
		List<ChanPin> chanpinList = new ArrayList<ChanPin>();
		Connection conn = DBManger.getConnection();
		Statement st=null;
		ResultSet rs=null;
		
		try {
			st=conn.createStatement();
			rs=st.executeQuery("select * from chanpin_copy where waiJianId="+cpId);
			while(rs.next()) {
				int pId = rs.getInt("chanPinId");
				String pName = rs.getString("chanPinName");
				String imgs = rs.getString("chanPinLoGo");
				ChanPin chanpin=new ChanPin(pId, pName, imgs);
				chanpinList.add(chanpin);
				
			}
			return chanpinList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManger.closeAll(conn, st, rs);
		}
	}
	
	public List<ChanPin> getChanPinList1(){
		List<ChanPin> chanpinList = new ArrayList<ChanPin>();
		Connection conn = DBManger.getConnection();
		Statement st=null;
		ResultSet rs=null;
		
		try {
			st=conn.createStatement();
			rs=st.executeQuery("select * from chanpin_copy ");
			while(rs.next()) {
				int pId = rs.getInt("chanPinId");
				String pName = rs.getString("chanPinName");
				String imgs = rs.getString("chanPinLoGo");
				ChanPin chanpin=new ChanPin(pId, pName, imgs);
				chanpinList.add(chanpin);
				
			}
			return chanpinList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManger.closeAll(conn, st, rs);
		}
	}
	
	public int deleteChanPinId(int cpId) {
		return DBManger.executeUpdate("DELETE from chanpin_copy where chanPinId ="+cpId);
		
		
	}
	
	
}
